1 A single case pattern in a textbook
We all know how a simple singleton pattern can be implemented: the constructor is declared private or protect to prevent being instantiated by an external function, and the internal holding of a private static
1 single-instance patterns in textbooksWe all know how a simple singleton pattern should be implemented: the constructor is declared as private or protect to prevent being instantiated by an external function, and a private static class pointer is
Preface
If the developer is developing or maintaining a servlet-based web application, it is recommended that you check the servlet specification. The content is helpful for Web application developers to understand the working mechanism of servlet
Baidu definition : Single case mode is a commonly used software design mode. In its core structure, there is only one special class that is called a singleton. The singleton mode ensures that there is only one instance of a class in the
1. What is thread safety?If a collection is thread-safe, then we don't have to consider concurrent access to this collection? (need to define their own Baidu, but difficult to understand)2. Drill down to the level of thread safety in the JVM.A
Problem:The Struts 2 Action object generates an instance for each request, so there is no thread safety issue.Spring's IOC container-managed bean defaults to a single instance, the state information of the last request processing is persisted, and
The thread is not secure. (In fact, I think the answer is: There are thread-safety issues that are better)
The reasons are as follows:
1th, first understand why threads are unsafe
1 Struts1 action is a single case, so there are thread-safety issues (
ArticleDirectory
I. Opening
Ii. Summary
Iii. Outline
Iv. Introduction to singleton Mode
V. Related application scenarios
Vi. Summary
VII. Series progress
8. next announcement
I. Opening
In fact, I did not intend to
All we've talked about is just a goal. That is, a thread-safe object can be published correctly.One: Thread closureWell, that's a good idea. If a variable is a state change done in a thread, then this variable is certainly thread-safe.We often use
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.